package com.usian.admin.controller.v1;

import com.usian.admin.service.WemediaNewsAutoService;
import com.usian.common.dtos.PageResult;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.admin.dtos.NewsAuthDto;
import com.usian.model.media.dtos.WmNewsResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自媒体文章人工审核控制层
 */
@RestController
@RequestMapping("/api/v1/news_auth")
public class NewsAuthController {

    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;

    /**
     * 分页条件查询自媒体文章列表
     */
    @PostMapping("/list")
    public PageResult<WmNewsResultDTO> findWmNewsPage(@RequestBody NewsAuthDto dto){
        return wemediaNewsAutoService.findWmNewsPage(dto);
    }

    /**
     * 根据id查询自媒体文章
     */
    @GetMapping("/one/{id}")
    public ResponseResult<WmNewsResultDTO> findById(@PathVariable("id")Integer id){
        return wemediaNewsAutoService.findWmNewsById(id);
    }

    /**
     * 人工审核通过
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto){
        wemediaNewsAutoService.updateWmNews(newsAuthDto.getId(),"人工审核通过",WmNewsResultDTO.Status.ADMIN_SUCCESS.getCode());
        return ResponseResult.ok();
    }

    /**
     * 人工审核未通过
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto){
        wemediaNewsAutoService.updateWmNews(newsAuthDto.getId(),newsAuthDto.getMsg(),WmNewsResultDTO.Status.FAIL.getCode());
        return ResponseResult.ok();
    }

}
